package com.kgc.controller;

import com.kgc.service.TbCatService;
import com.kgc.utils.ItripResult;
import com.kgc.utils.ResultTable;
import com.kgc.utils.TreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class TbCatController {
    @Autowired
    private TbCatService tbCatService;
    @RequestMapping("tbc/list")
    @ResponseBody
    public ResultTable list( @RequestParam(value = "page",required = false,defaultValue = "1")int   page,
                             @RequestParam(value = "pageSize",required = false,defaultValue = "3")int   pageSize){

        ResultTable all = tbCatService.findAll(page,pageSize);
        return all;
    }
    @RequestMapping("tbc/tree")
    @ResponseBody
    public Map find(){
        HashMap<Object, Object> map = new HashMap<>();
        List<TreeNode> tree = tbCatService.findTree();
        map.put("data",tree);
        return map;
    }
    @RequestMapping("/contentCat/del")
    @ResponseBody
    public Map find1(Long id){
        HashMap<Object, Object> map = new HashMap<>();
        tbCatService.deleteById(id);
        map.put("mgs","删除成功");
        map.put("code",0);
        return map;
    }
    @RequestMapping("/contentcat/add")
    @ResponseBody
    public ItripResult addCat(Long pid, String name){

        return tbCatService.addContentCategory(pid,name);
    }
    @RequestMapping("/contentcat/update")
    @ResponseBody
    public ItripResult updateCat(Long id,String name){

        return tbCatService.updateContentCategory(id,name);
    }
    //删除


}

